From: Marco Trevisan (TreviƱo) Date: Tue, 30 Apr 2024 23:17:10 +0000 (+0200) Subject: js/environment: Add GLib spawn async overrides warning when using child setup X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~226^2^2~116 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=494be307649f20aaed53113f3c1ff740980a5992;p=gnome-shell.git js/environment: Add GLib spawn async overrides warning when using child setup Using child setup functions is unsafe in gjs code so let's warn if this happens so that extensions using a similar codepath are warned. This could be also part of gjs, but we provide a shell override since we have alternatives to log about. Part-of: --- diff --git a/js/ui/environment.js b/js/ui/environment.js index 4150542db..4ce70367e 100644 --- a/js/ui/environment.js +++ b/js/ui/environment.js @@ -345,6 +345,24 @@ if (slowdownEnv) { St.Settings.get().slow_down_factor = factor; } +function wrapSpawnFunction(func) { + const originalFunc = GLib[func]; + return function (workingDirectory, argv, envp, flags, childSetup, ...args) { + if (childSetup) { + logError(new Error(`Using child GLib.${func} with a GLib.SpawnChildSetupFunc ` + + 'is unsafe and may dead-lock, thus it should never be used from JavaScript. ' + + `Shell.${func} can be used to perform default actions or an ` + + 'async-signal-safe alternative should be used instead')); + } + + return originalFunc(workingDirectory, argv, envp, flags, childSetup, ...args); + }; +} +GLib.spawn_async = wrapSpawnFunction('spawn_async'); +GLib.spawn_async_with_pipes = wrapSpawnFunction('spawn_async_with_pipes'); +GLib.spawn_async_with_fds = wrapSpawnFunction('spawn_async_with_fds'); +GLib.spawn_async_with_pipes_and_fds = wrapSpawnFunction('spawn_async_with_pipes_and_fds'); + // OK, now things are initialized enough that we can import shell JS const Format = imports.format;